<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="设备id" prop="devId">
      <el-input v-model="dataForm.devId" placeholder="设备id"></el-input>
    </el-form-item>
    <el-form-item label="设备编号" prop="devSn">
      <el-input v-model="dataForm.devSn" placeholder="设备编号"></el-input>
    </el-form-item>
    <el-form-item label="运行速度" prop="runSpeed">
      <el-input v-model="dataForm.runSpeed" placeholder="运行速度"></el-input>
    </el-form-item>
    <el-form-item label="电机温度" prop="devTmp">
      <el-input v-model="dataForm.devTmp" placeholder="电机温度"></el-input>
    </el-form-item>
    <el-form-item label="声音分贝" prop="devVoice">
      <el-input v-model="dataForm.devVoice" placeholder="声音分贝"></el-input>
    </el-form-item>
    <el-form-item label="开门次数" prop="openCount">
      <el-input v-model="dataForm.openCount" placeholder="开门次数"></el-input>
    </el-form-item>
    <el-form-item label="总运行时间" prop="runTime">
      <el-input v-model="dataForm.runTime" placeholder="总运行时间"></el-input>
    </el-form-item>
    <el-form-item label="当班时间" prop="dutyTime">
      <el-input v-model="dataForm.dutyTime" placeholder="当班时间"></el-input>
    </el-form-item>
    <el-form-item label="累计时间" prop="totalTime">
      <el-input v-model="dataForm.totalTime" placeholder="累计时间"></el-input>
    </el-form-item>
    <el-form-item label="当班产量" prop="dutyOutput">
      <el-input v-model="dataForm.dutyOutput" placeholder="当班产量"></el-input>
    </el-form-item>
    <el-form-item label="累计产量" prop="totalOutput">
      <el-input v-model="dataForm.totalOutput" placeholder="累计产量"></el-input>
    </el-form-item>
    <el-form-item label="总运行速度" prop="totalRunTime">
      <el-input v-model="dataForm.totalRunTime" placeholder="总运行速度"></el-input>
    </el-form-item>
    <el-form-item label="药品信息显示" prop="drugInfo">
      <el-input v-model="dataForm.drugInfo" placeholder="药品信息显示"></el-input>
    </el-form-item>
    <el-form-item label="端口预留信息显示" prop="portInfo">
      <el-input v-model="dataForm.portInfo" placeholder="端口预留信息显示"></el-input>
    </el-form-item>
    <el-form-item label="设备开关机状态(0关闭,1开启)" prop="devSwitchState">
      <el-input v-model="dataForm.devSwitchState" placeholder="设备开关机状态(0关闭,1开启)"></el-input>
    </el-form-item>
    <el-form-item label="急停信号(0无)" prop="stopSign">
      <el-input v-model="dataForm.stopSign" placeholder="急停信号(0无)"></el-input>
    </el-form-item>
    <el-form-item label="缺料信号(0无)" prop="missProSign">
      <el-input v-model="dataForm.missProSign" placeholder="缺料信号(0无)"></el-input>
    </el-form-item>
    <el-form-item label="缺囊信号(0无)" prop="missBagSign">
      <el-input v-model="dataForm.missBagSign" placeholder="缺囊信号(0无)"></el-input>
    </el-form-item>
    <el-form-item label="气压信号(0无)" prop="airSign">
      <el-input v-model="dataForm.airSign" placeholder="气压信号(0无)"></el-input>
    </el-form-item>
    <el-form-item label="变频故障信号(0无)" prop="errorSign">
      <el-input v-model="dataForm.errorSign" placeholder="变频故障信号(0无)"></el-input>
    </el-form-item>
    <el-form-item label="产品代码" prop="proCode">
      <el-input v-model="dataForm.proCode" placeholder="产品代码"></el-input>
    </el-form-item>
    <el-form-item label="产品名称" prop="proName">
      <el-input v-model="dataForm.proName" placeholder="产品名称"></el-input>
    </el-form-item>
    <el-form-item label="产品批号" prop="proNum">
      <el-input v-model="dataForm.proNum" placeholder="产品批号"></el-input>
    </el-form-item>
    <el-form-item label="操作员级别" prop="operatorLevel">
      <el-input v-model="dataForm.operatorLevel" placeholder="操作员级别"></el-input>
    </el-form-item>
    <el-form-item label="操作员" prop="operatorName">
      <el-input v-model="dataForm.operatorName" placeholder="操作员"></el-input>
    </el-form-item>
    <el-form-item label="手动/自动 (0自动/1手动)" prop="switchWay">
      <el-input v-model="dataForm.switchWay" placeholder="手动/自动 (0自动/1手动)"></el-input>
    </el-form-item>
    <el-form-item label="主机点动(0否)" prop="pointAction">
      <el-input v-model="dataForm.pointAction" placeholder="主机点动(0否)"></el-input>
    </el-form-item>
    <el-form-item label="主机联动(0否)" prop="linkAction">
      <el-input v-model="dataForm.linkAction" placeholder="主机联动(0否)"></el-input>
    </el-form-item>
    <el-form-item label="真空泵点动(0否)" prop="airPointAction">
      <el-input v-model="dataForm.airPointAction" placeholder="真空泵点动(0否)"></el-input>
    </el-form-item>
    <el-form-item label="真空泵联动(0否)" prop="airLinkAction">
      <el-input v-model="dataForm.airLinkAction" placeholder="真空泵联动(0否)"></el-input>
    </el-form-item>
    <el-form-item label="切换前工作时间" prop="beforeSwitchTime">
      <el-input v-model="dataForm.beforeSwitchTime" placeholder="切换前工作时间"></el-input>
    </el-form-item>
    <el-form-item label="切换后工作时间" prop="afterSwitchTime">
      <el-input v-model="dataForm.afterSwitchTime" placeholder="切换后工作时间"></el-input>
    </el-form-item>
    <el-form-item label="放料时间" prop="pushTime">
      <el-input v-model="dataForm.pushTime" placeholder="放料时间"></el-input>
    </el-form-item>
    <el-form-item label="空囊上料延时时间" prop="airDelayTime">
      <el-input v-model="dataForm.airDelayTime" placeholder="空囊上料延时时间"></el-input>
    </el-form-item>
    <el-form-item label="主机延时时间" prop="hostDelayTime">
      <el-input v-model="dataForm.hostDelayTime" placeholder="主机延时时间"></el-input>
    </el-form-item>
    <el-form-item label="缺料延时时间" prop="missproDelayTime">
      <el-input v-model="dataForm.missproDelayTime" placeholder="缺料延时时间"></el-input>
    </el-form-item>
    <el-form-item label="缺囊延时时间" prop="missbagDelayTime">
      <el-input v-model="dataForm.missbagDelayTime" placeholder="缺囊延时时间"></el-input>
    </el-form-item>
    <el-form-item label="加料电机延时时间" prop="addDelayTime">
      <el-input v-model="dataForm.addDelayTime" placeholder="加料电机延时时间"></el-input>
    </el-form-item>
    <el-form-item label="经纬度" prop="terminalGps">
      <el-input v-model="dataForm.terminalGps" placeholder="经纬度"></el-input>
    </el-form-item>
    <el-form-item label="终端温度" prop="terminalTmp">
      <el-input v-model="dataForm.terminalTmp" placeholder="终端温度"></el-input>
    </el-form-item>
    <el-form-item label="终端状态" prop="terminalState">
      <el-input v-model="dataForm.terminalState" placeholder="终端状态"></el-input>
    </el-form-item>
    <el-form-item label="终端key" prop="terminalKey">
      <el-input v-model="dataForm.terminalKey" placeholder="终端key"></el-input>
    </el-form-item>
    <el-form-item label="终端名称" prop="terminalName">
      <el-input v-model="dataForm.terminalName" placeholder="终端名称"></el-input>
    </el-form-item>
    <el-form-item label="终端连接状态" prop="terminalConnectState">
      <el-input v-model="dataForm.terminalConnectState" placeholder="终端连接状态"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          userId: '',
          devId: '',
          devSn: '',
          runSpeed: '',
          devTmp: '',
          devVoice: '',
          openCount: '',
          runTime: '',
          dutyTime: '',
          totalTime: '',
          dutyOutput: '',
          totalOutput: '',
          totalRunTime: '',
          drugInfo: '',
          portInfo: '',
          devSwitchState: '',
          stopSign: '',
          missProSign: '',
          missBagSign: '',
          airSign: '',
          errorSign: '',
          proCode: '',
          proName: '',
          proNum: '',
          operatorLevel: '',
          operatorName: '',
          switchWay: '',
          pointAction: '',
          linkAction: '',
          airPointAction: '',
          airLinkAction: '',
          beforeSwitchTime: '',
          afterSwitchTime: '',
          pushTime: '',
          airDelayTime: '',
          hostDelayTime: '',
          missproDelayTime: '',
          missbagDelayTime: '',
          addDelayTime: '',
          terminalGps: '',
          terminalTmp: '',
          terminalState: '',
          terminalKey: '',
          terminalName: '',
          terminalConnectState: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          devId: [
            { required: true, message: '设备id不能为空', trigger: 'blur' }
          ],
          devSn: [
            { required: true, message: '设备编号不能为空', trigger: 'blur' }
          ],
          runSpeed: [
            { required: true, message: '运行速度不能为空', trigger: 'blur' }
          ],
          devTmp: [
            { required: true, message: '电机温度不能为空', trigger: 'blur' }
          ],
          devVoice: [
            { required: true, message: '声音分贝不能为空', trigger: 'blur' }
          ],
          openCount: [
            { required: true, message: '开门次数不能为空', trigger: 'blur' }
          ],
          runTime: [
            { required: true, message: '总运行时间不能为空', trigger: 'blur' }
          ],
          dutyTime: [
            { required: true, message: '当班时间不能为空', trigger: 'blur' }
          ],
          totalTime: [
            { required: true, message: '累计时间不能为空', trigger: 'blur' }
          ],
          dutyOutput: [
            { required: true, message: '当班产量不能为空', trigger: 'blur' }
          ],
          totalOutput: [
            { required: true, message: '累计产量不能为空', trigger: 'blur' }
          ],
          totalRunTime: [
            { required: true, message: '总运行速度不能为空', trigger: 'blur' }
          ],
          drugInfo: [
            { required: true, message: '药品信息显示不能为空', trigger: 'blur' }
          ],
          portInfo: [
            { required: true, message: '端口预留信息显示不能为空', trigger: 'blur' }
          ],
          devSwitchState: [
            { required: true, message: '设备开关机状态(0关闭,1开启)不能为空', trigger: 'blur' }
          ],
          stopSign: [
            { required: true, message: '急停信号(0无)不能为空', trigger: 'blur' }
          ],
          missProSign: [
            { required: true, message: '缺料信号(0无)不能为空', trigger: 'blur' }
          ],
          missBagSign: [
            { required: true, message: '缺囊信号(0无)不能为空', trigger: 'blur' }
          ],
          airSign: [
            { required: true, message: '气压信号(0无)不能为空', trigger: 'blur' }
          ],
          errorSign: [
            { required: true, message: '变频故障信号(0无)不能为空', trigger: 'blur' }
          ],
          proCode: [
            { required: true, message: '产品代码不能为空', trigger: 'blur' }
          ],
          proName: [
            { required: true, message: '产品名称不能为空', trigger: 'blur' }
          ],
          proNum: [
            { required: true, message: '产品批号不能为空', trigger: 'blur' }
          ],
          operatorLevel: [
            { required: true, message: '操作员级别不能为空', trigger: 'blur' }
          ],
          operatorName: [
            { required: true, message: '操作员不能为空', trigger: 'blur' }
          ],
          switchWay: [
            { required: true, message: '手动/自动 (0自动/1手动)不能为空', trigger: 'blur' }
          ],
          pointAction: [
            { required: true, message: '主机点动(0否)不能为空', trigger: 'blur' }
          ],
          linkAction: [
            { required: true, message: '主机联动(0否)不能为空', trigger: 'blur' }
          ],
          airPointAction: [
            { required: true, message: '真空泵点动(0否)不能为空', trigger: 'blur' }
          ],
          airLinkAction: [
            { required: true, message: '真空泵联动(0否)不能为空', trigger: 'blur' }
          ],
          beforeSwitchTime: [
            { required: true, message: '切换前工作时间不能为空', trigger: 'blur' }
          ],
          afterSwitchTime: [
            { required: true, message: '切换后工作时间不能为空', trigger: 'blur' }
          ],
          pushTime: [
            { required: true, message: '放料时间不能为空', trigger: 'blur' }
          ],
          airDelayTime: [
            { required: true, message: '空囊上料延时时间不能为空', trigger: 'blur' }
          ],
          hostDelayTime: [
            { required: true, message: '主机延时时间不能为空', trigger: 'blur' }
          ],
          missproDelayTime: [
            { required: true, message: '缺料延时时间不能为空', trigger: 'blur' }
          ],
          missbagDelayTime: [
            { required: true, message: '缺囊延时时间不能为空', trigger: 'blur' }
          ],
          addDelayTime: [
            { required: true, message: '加料电机延时时间不能为空', trigger: 'blur' }
          ],
          terminalGps: [
            { required: true, message: '经纬度不能为空', trigger: 'blur' }
          ],
          terminalTmp: [
            { required: true, message: '终端温度不能为空', trigger: 'blur' }
          ],
          terminalState: [
            { required: true, message: '终端状态不能为空', trigger: 'blur' }
          ],
          terminalKey: [
            { required: true, message: '终端key不能为空', trigger: 'blur' }
          ],
          terminalName: [
            { required: true, message: '终端名称不能为空', trigger: 'blur' }
          ],
          terminalConnectState: [
            { required: true, message: '终端连接状态不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/zhiyao/zydevicedata01/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm = data.data.zyDeviceData01
                // this.dataForm.userId = data.zydevicedata01.userId
                // this.dataForm.devId = data.zydevicedata01.devId
                // this.dataForm.devSn = data.zydevicedata01.devSn
                // this.dataForm.runSpeed = data.zydevicedata01.runSpeed
                // this.dataForm.devTmp = data.zydevicedata01.devTmp
                // this.dataForm.devVoice = data.zydevicedata01.devVoice
                // this.dataForm.openCount = data.zydevicedata01.openCount
                // this.dataForm.runTime = data.zydevicedata01.runTime
                // this.dataForm.dutyTime = data.zydevicedata01.dutyTime
                // this.dataForm.totalTime = data.zydevicedata01.totalTime
                // this.dataForm.dutyOutput = data.zydevicedata01.dutyOutput
                // this.dataForm.totalOutput = data.zydevicedata01.totalOutput
                // this.dataForm.totalRunTime = data.zydevicedata01.totalRunTime
                // this.dataForm.drugInfo = data.zydevicedata01.drugInfo
                // this.dataForm.portInfo = data.zydevicedata01.portInfo
                // this.dataForm.devSwitchState = data.zydevicedata01.devSwitchState
                // this.dataForm.stopSign = data.zydevicedata01.stopSign
                // this.dataForm.missProSign = data.zydevicedata01.missProSign
                // this.dataForm.missBagSign = data.zydevicedata01.missBagSign
                // this.dataForm.airSign = data.zydevicedata01.airSign
                // this.dataForm.errorSign = data.zydevicedata01.errorSign
                // this.dataForm.proCode = data.zydevicedata01.proCode
                // this.dataForm.proName = data.zydevicedata01.proName
                // this.dataForm.proNum = data.zydevicedata01.proNum
                // this.dataForm.operatorLevel = data.zydevicedata01.operatorLevel
                // this.dataForm.operatorName = data.zydevicedata01.operatorName
                // this.dataForm.switchWay = data.zydevicedata01.switchWay
                // this.dataForm.pointAction = data.zydevicedata01.pointAction
                // this.dataForm.linkAction = data.zydevicedata01.linkAction
                // this.dataForm.airPointAction = data.zydevicedata01.airPointAction
                // this.dataForm.airLinkAction = data.zydevicedata01.airLinkAction
                // this.dataForm.beforeSwitchTime = data.zydevicedata01.beforeSwitchTime
                // this.dataForm.afterSwitchTime = data.zydevicedata01.afterSwitchTime
                // this.dataForm.pushTime = data.zydevicedata01.pushTime
                // this.dataForm.airDelayTime = data.zydevicedata01.airDelayTime
                // this.dataForm.hostDelayTime = data.zydevicedata01.hostDelayTime
                // this.dataForm.missproDelayTime = data.zydevicedata01.missproDelayTime
                // this.dataForm.missbagDelayTime = data.zydevicedata01.missbagDelayTime
                // this.dataForm.addDelayTime = data.zydevicedata01.addDelayTime
                // this.dataForm.terminalGps = data.zydevicedata01.terminalGps
                // this.dataForm.terminalTmp = data.zydevicedata01.terminalTmp
                // this.dataForm.terminalState = data.zydevicedata01.terminalState
                // this.dataForm.terminalKey = data.zydevicedata01.terminalKey
                // this.dataForm.terminalName = data.zydevicedata01.terminalName
                // this.dataForm.terminalConnectState = data.zydevicedata01.terminalConnectState
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/zhiyao/zydevicedata01/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                zyDeviceData01: this.dataForm
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  // duration: 1500,
                  duration: 500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
